// @ts-ignore
/* eslint-disable */
import { requestAuth } from '@/utils/request';

/** 获取资源整树 */
export async function fetchResourceTree() {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/getResourceTreeList',
    data: {},
  });
}

/** 获取资源目录树（只有目录） */
export async function fetchResourceCatalogueFromTree() {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/getResourceDirectoryTreeList',
    data: {},
  });
}

/** 获取资源菜单树（只返回有效目录和菜单，角色资源授权使用该接口） */
export async function fetchValidResourceFromTree() {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/getResourceSoundTreeList',
    data: {},
  });
}

/** 添加资源 */
export async function addResource(data: {
  parentId: string;
  menuIcon: string;
  title: string;
  type: string; // 资源类型
  resSort: number;
  resStatus: string; // 资源状态
  routePath?: string; // 菜单路由地址
  sourceParams?: {}; // 通配菜单的来源参数:JSON.stringify({key: value})
  keepAlive?: boolean; // 菜单是否缓存
  description?: string;
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/save',
    data,
  });
}

/** 修改资源 */
export async function modifyResource(data: {
  id: string;
  menuIcon: string;
  title: string;
  type: string;
  resSort: number;
  resStatus: string; // 资源状态
  routePath?: string; // 菜单路由地址
  keepAlive: boolean; // 菜单是否缓存
  sourceParams?: string; // 通配菜单的来源参数:JSON.stringify({key: value})
  parentId?: string;
  description?: string;
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/update',
    data,
  });
}

/** 删除资源 */
export async function deleteResource(data: { id: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/delete',
    data,
  });
}

/** 批量删除资源 */
export async function batchDeleteResource(data: { ids: string[] }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resource/deleteBatch',
    data,
  });
}

/** 获取菜单下的按钮/接口配置 */
export async function fetchResourceMenuActionItems(data: { resourceId: string }) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resourceComponent/list',
    data,
  });
}

/** 更新菜单下的按钮/接口配置 */
export async function updateResourceMenuActionItems(data: {
  resourceId: string; // 菜单id
  list: {
    componentKey: string; // 操作key，菜单下唯一
    componentName: string; // 操作名称
    description?: string; // 操作描述
    resPath?: string; // 后端接口服务地址
  }[];
}) {
  return requestAuth({
    method: 'POST',
    url: '/api/system/resourceComponent/update',
    data,
  });
}
